<extend name="Layout::index"/>
<block name="main">
    <div class="panel panel-primary" id="js_album">
        <div class="panel-heading">
            相册系统
        </div>
        <div class="panel-body">
            <notempty name="list">
                <foreach name="list" item="v">
            <div class="col-xs-12 col-sm-6 col-md-4">
                <div class="thumbnail">

                    <img src="__ROOT__{$v['face']}" alt="" style="height:350px;">
                    <div class="caption">
                        <h3>{$v['name']}</h3>
                        <p><a class="btn btn-primary js_check" role="button" pid="{$v['id']}">查看详情</a></p>
                    </div>

                </div>
            </div>
                </foreach>
                <else/>
                没有相册
            </notempty>
        </div>
    </div>
    <div class="modal fade" id="myModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">添加相册</h4>
                </div>
                <div class="modal-body">
                    <form action="{:U('Index/addalbum')}" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1">相册名称</label>
                            <input type="text" name="name" class="form-control" id="exampleInputEmail1" placeholder="album">
                        </div>
                        <div class="form-group">
                            <label for="exampleInputFile">相册</label>
                            <input type="file" id="exampleInputFile" name="face">
                            <p class="help-block">Example block-level help text here.</p>
                        </div>
                        <button type="submit" class="btn btn-primary">添加</button>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <script>
        $("#js_addalbum").click(function(){
            $('#myModal').modal('show');
        })

        $(".js_check").each(function(){
            $(this).click(function() {
                var id = $(this).attr('pid');
                 //alert(id);
                $.ajax({
                    type: "POST",        //发送格式
                    url: "{:U('showphoto')}",   //发送到哪里
                    async: true,        // 设置格式(异步)   默认异步
                    data: {'id': id},  //发送的参数
                    success: function (data) {
                        $("#js_album").replaceWith(data);
                    },
                    error: function () {
                        //请求出错处理
                        alert("Error!");
                    }
                })
            })
        })
    </script>
</block>